#!/usr/bin/perl -w


use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;


##### Check arguments
if(($#ARGV + 1) != 2) {
	print "$#ARGV \n";	
	usage();
}


##### Define variables
my $date = $ARGV[0];
my $inputFolder = "$ARGV[1]";
my $numArgs = $#ARGV + 1;
my $workbook = Spreadsheet::WriteExcel->new("Evaluation_$date.xls");
my $nbrOfWorksheets = 0;
my @worksheets = ();
my @files = ();
my $count = 1;
my $backslash = "\\";


##### Check if input folder exists
if(!(-d $inputFolder)) { 
	print "Error: $inputFolder doesen't exists\n";
	exit();
}


##### Check if input path includes "\"
my $lastCharacter = substr $inputFolder,-1,1;
if($lastCharacter ne $backslash) {	
	 $inputFolder = $inputFolder . $backslash;
}


##### Parse input folder & read files
opendir(DIR, $inputFolder) || die("Cannot open input directory");

while (my $file = readdir(DIR)) {	
	
    next if ($file =~ m/^\./);	
	
	my $absPath = $inputFolder . $file;	
	
	open(FILE, $absPath) || die("Could not open file!");
	my @rawData=<FILE>; 
	
	print @rawData;
	
	#$worksheets[$count] = $workbook->addworksheet("$date($count)");
	#$worksheets[0]->write_row('A1', @rawData);

	$count = $count + 1;
	close(FILE);
}



##### Fill sheet with data
#$worksheets[0]->write('A2', '=COUNT(C:C)');
#$worksheets[1]->write('A2', '=COUNT(C:C)');



##### Subroutine for usage of this script
sub usage {
	print "Error: Call syntax incorrect\n";
	print "Usage: perl parser.pl date input_folder\n";
  	exit();
}

